var app = getApp();
Page({
  data: {
    stars: [0, 1, 2, 3, 4],
    normalSrc: '../../images/normal.png',
    selectedSrc: '../../images/selected.png',
    point: 0,//描述相符评分
    point2: 0,//服务态度评分
    arraydetail: [],
    orderId: 0,
    author: 'Lotus'
  },
  formSubmit: function (e) {
    var that = this;
    //var keyword = e.detail.value;  
    //console.log('form发生了submit事件，携带数据为：',e.detail.value);
    const params = e.detail.value
    if (!this.WxValidate.checkForm(e)) {
      const error = this.WxValidate.errorList[0]
      //console.log("param:" + error.param+"msg:" + error.msg)
      wx.showToast({
        title: error.msg,
        icon: 'error',
        duration: 2000
      })
      return false
    }

    var service = 'Order.commentOrder';
    var orderId = that.data.orderId;
    var point = that.data.point;
    var point2 = that.data.point2; 
    var contents = e.detail.value.contents;

    if(point<1){
      wx.showToast({
        title: '请输入描述相符：',
        icon: 'error',
        duration: 2000
      })
      return false;
    }
    if(point2<1){
      wx.showToast({
        title: '请输入服务态度：：',
        icon: 'error',
        duration: 2000
      })
      return false;
    }
    wx.request({
      method: 'POST',
      url: app.globalData.APIURL,
      data: { service: service, openId: app.globalData.openId, orderId: orderId, point: point, point2: point2, contents: contents },
      header: { 'Content-Type': 'application/x-www-form-urlencoded' },
      success: function (res) {
        console.log("success:" + res.data.data)
        if (!res.data.data.code) {
          wx.redirectTo({
            url: 'orderlist'
          })
        }
      },
      fail: function (res) {
        console.log("fail:" + res)
      },
    })

  },
  //点击整颗星
  selectStar: function (e) {
    var point = e.currentTarget.dataset.key
    this.setData({
      point: point
    })
  },

  selectStar2: function (e) {
    var point2 = e.currentTarget.dataset.key
    this.setData({
      point2: point2
    })
  },


  getlist: function () {
    var that = this;
    var service = 'Order.getOrderInfo';
    var orderId = that.data.orderId;
    wx.request({
      method: 'POST',
      url: app.globalData.APIURL,
      data: { service: service, openId: app.globalData.openId, orderId: orderId },
      header: { 'Content-Type': 'application/x-www-form-urlencoded' },
      success: function (res) {
        //console.log("success:" + res.data.data);    
        if (!res.data.data.code) {
          that.setData({
            arraydetail: res.data.data.info
          })
        }
      },
      fail: function (res) {
        console.log("fail:" + res);
      },
    })

  },
  onLoad: function (options) {
    var that = this;
    if (options.fromInviteCode) {
      app.globalData.fromInviteCode=options.fromInviteCode;
    }
    app.appstart();
    if (options.orderId) {
      that.setData({ orderId: options.orderId });
    }
    that.getlist();

      that.WxValidate = app.WxValidate({
      contents: {
        required: true,
        minlength: 2,
      }
    }, {
        contents: {
          required: '请输入评价',
        }
      })
  }
})